package leader.action;

import java.util.List;

import leader.service.DirectTeacherService;
import leader.service.LeaderService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Expertclass;
import teacher.bean.Teacher;
import tools.StringDate;

public class AddTeacherAction {
	private Teacher teacher;
	private int[] experid;
	private String flag;
	
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	
	public int[] getExperid() {
		return experid;
	}
	public void setExperid(int[] experid) {
		this.experid = experid;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public String execute(){
		flag = "error";
		System.out.println("=================添加教师开始================");
		StringDate date = new StringDate();
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		System.out.println(new DirectTeacherService().getCountOfTeacherByUser(teacher.getUser().toString()));
		if(new DirectTeacherService().getCountOfTeacherByUser(teacher.getUser().toString()) == 0) {
			teacher.setPassword(teacher.getUser());
			teacher.setDirection(lea.getDirection());
			teacher.setSubject(lea.getSubject());
			teacher.setDuty("0");
			teacher.setDegree(0);
			teacher.setOnline(0);
			teacher.setBirthday(date.StringToDate("1900-01-01"));
			teacher.setFurStud("0");
			teacher.setTopSchool("0");
			teacher.setTopMajor("");
			teacher.setMail("XXX@zjut.edu.cn");
			teacher.setPower(2);
			teacher.setInSubDate(date.StringToDate("1900-01-01"));
			LeaderService LS = new LeaderService();
			LS.insertTeacher(teacher);
			flag = "success";
			System.out.println("=================添加成功===============");
		} else {
			System.out.println("=================添加不成功===============");
		}
		return "success";
	}
}
